package com.pacy.pacybaseproject.adapters;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.baidu.mapapi.search.route.MassTransitRouteLine;
import com.baidu.mapapi.search.route.TransitRouteLine;
import com.blankj.utilcode.util.TimeUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.pacy.pacybaseproject.R;
import com.pacy.pacybaseproject.utils.XUtils;

import java.util.List;

import me.goldze.mvvmhabit.utils.DateUtil;
import me.goldze.mvvmhabit.utils.KLog;

/**
 * @author PACY
 * @date 2024/1/3
 * description:
 */
public class RoutingTravelAdapter extends BaseQuickAdapter<MassTransitRouteLine, BaseViewHolder> {
    private LinearLayout stationTemp;
    public RoutingTravelAdapter() {
        super(R.layout.routing_travel_item_view);
    }

    @Override
    protected void convert(BaseViewHolder holder, MassTransitRouteLine s) {
        stationTemp=holder.getView(R.id.stationTemp_lin);
        stationTemp.removeAllViews();
        int distance=0;//步行距离
        int stationNum=0;//车站数量
        MassTransitRouteLine.TransitStep oneStep = null;
        for (List<MassTransitRouteLine.TransitStep> transitSteps : s.getNewSteps()) {
            for (MassTransitRouteLine.TransitStep transitStep : transitSteps) {
                switch (transitStep.getVehileType()){
                    // ESTEP_TRAIN(1), 火车
                    // ESTEP_PLANE(2), 飞机
                    // ESTEP_BUS(3),   公交车
                    // ESTEP_DRIVING(4), 驾车
                    // ESTEP_WALK(5), 步行
                    // ESTEP_COACH 大巴
                    case ESTEP_TRAIN:
                    case ESTEP_PLANE:
                    case ESTEP_COACH:
                    case ESTEP_DRIVING:

                        return;
                    case ESTEP_BUS:
                        if(oneStep==null){
                            oneStep=transitStep;
                        }
                        stationNum++;
                        View view= LayoutInflater.from(getContext()).inflate(R.layout.routing_station_temp_view,null);
                        TextView lineName_tv=view.findViewById(R.id.lineName_tv);
                        lineName_tv.setText(transitStep.getBusInfo().getName());
                        stationTemp.addView(view);
                        break;
                    //步行
                    case ESTEP_WALK:
                        distance+=transitStep.getDistance();
                        break;
                }
//                KLog.i("换乘说明---"+transitStep.getInstructions());
            }

        }
        holder.setText(R.id.time_tv, DateUtil.secondToDate(s.getDuration()))
                .setText(R.id.content_tv,stationNum+"站 · "+XUtils.doubleTrans(s.getPrice())+"元 · "+oneStep.getBusInfo().getDepartureStation()+"上车")
                .setText(R.id.distance_tv, XUtils.formatDistance(distance));
    }
}
